alter table Cms_Wsm_InstrumentAssembly
add GuaranteebeginDate datetime null

go
alter table Cms_Wsm_InstrumentAssembly
add ReturnVisitbeginDate datetime null

alter table Cms_Wsm_InstrumentAssembly
add CalibrationbeginDate datetime null

go
alter table Cms_Wsm_InstrumentAssembly
add ReadNumType int null

go

update Cms_Wsm_InstrumentAssembly
set ReadNumType = b.ReadNumType
from Cms_Wsm_InstrumentAssembly a
inner join
(
select MaintainID,MAX(ReadNumType) as ReadNumType from Cms_Wsm_InstrumentRecord group by MaintainID 
) b on a.MaintainID =  b.MaintainID

go


--select ReadNumType from Cms_Wsm_InstrumentAssembly
--select MaintainID,MAX(ReadNumType) as ReadNumType from Cms_Wsm_InstrumentRecord group by MaintainID order by 2

